package com.wendy.controller;

import com.wendy.utils.ResponseUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhuwending
 */
@Controller
public class LoginController {

    @GetMapping(value = "/login")
    @ResponseBody
    public Object authenticationLogin(HttpServletRequest request) {
        String header = request.getHeader("X-Requested-With");
        boolean isAjax = StringUtils.isNotEmpty(header) && "XMLHttpRequest".equalsIgnoreCase(header);
        if (isAjax) {
            return ResponseUtil.errorResponse("登录失效，请重新登录");
        }
        return new ModelAndView("/login");
    }
}
